package client;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

import msg.CreateMsg;

public class CloudKeeper {
	public static void main(String[] args) {
		while (true) {
			Socket socket = null;
			try {
				socket = new Socket("127.0.0.1", 10055);
				InputStream is = socket.getInputStream();
				OutputStream os = socket.getOutputStream();

				CreateMsg msg = new CreateMsg("/c/d/e/f/g", "this is content");

				os.write(msg.encode());
				socket.shutdownOutput();

				int count;
				byte[] buffer = new byte[1024];
				while ((count = is.read(buffer)) != -1) {
					System.out.println(new String(buffer, 0, count));
				}

				Thread.sleep(1000);
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				try {
					socket.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}